<!DOCTYPE html>
<html lang="en" class="svg no-js">
<head>
    <meta charset="utf-8" />
    <!--[if IE ]>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <![endif]-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="Language" content="en">

    <title>MySQL :: MySQL 8.0 Reference Manual :: 12.10 Cast Functions and Operators</title>
    <link rel="stylesheet" media="all" href="css/main-20190125.min.css" />
            <link rel="stylesheet" media="all" href="css/docs-20190125.min.css" />
    
    
    <link rel="stylesheet" media="print" href="css/print-20190125.min.css" />

    
    
    
    
            <link rel="contents" href="index.html" title="MySQL 8.0 Reference Manual" />
<link rel="start" href="index.html" title="MySQL 8.0 Reference Manual" />
<link rel="prev" href="fulltext-search-mecab.html" title="12.9.9 MeCab Full-Text Parser Plugin" />
<link rel="next" href="xml-functions.html?ff=nopfpls" title="12.11 XML Functions" />
<link rel="up" href="functions.html" title="12 Functions and Operators" />

    
    <link rel="shortcut icon" href="favicon.ico" />
    <script>(function(H){ H.className=H.className.replace(/\bno-js\b/,'js') })(document.documentElement)</script>
    <script src="js/site-20181120.min.js"></script>

    
    
    
    <!--[if lt IE 9]>
        <script src="https://labs.mysql.com/common/js/polyfills/html5shiv-printshiv-3.7.2.min.js"></script>
        <script src="https://labs.mysql.com/common/js/polyfills/respond-1.4.2.min.js"></script>
    <![endif]-->
        <!--[if IE 9]>
        <style>#docs-sidebar-toc { box-sizing: content-box; }</style>
    <![endif]-->
    </head>

<body class="no-sidebar full-page dev">
<div class="page-wrapper">
    <header>

                        <a href="https://dev.mysql.com/" aria-label="Home" title="MySQL" id="l1-home-link"></a>
        
        <div id="l1-nav-container">
            <div id="l1-line1">
                <div id="l1-auth-links">
                    <a href="https://www.mysql.com/about/contact/"><b>Contact MySQL</b></a>
                    <span id="l1-contact-separator">&nbsp;|&nbsp;</span>
                    <span id="l1-contact-separator-br"><br /></span>
                                             <a href="https://dev.mysql.com/auth/login/?dest=https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F8.0%2Fen%2Fcast-functions.html">Login</a> &nbsp;|&nbsp;
                         <a href="https://dev.mysql.com/auth/register/">Register</a>
                                    </div>
                <div id="l1-lhs">
                    <div id="l1-slogan">
                        The world's most popular open source database
                    </div>
                    <div id="l1-search-box">
                        <form id="l1-search-form" method="get" action="https://www.oracle.com/search/results">
                        <input type="hidden" name="cat" value="mysql" />
                        <input type="hidden" name="Ntk" value="SI-ALL5" />
                        <input id="l1-search-input" type="search" class="icon-search" placeholder="Search" aria-label="Search" name="Ntt" />
                        </form>
                    </div>
                </div>
            </div>
            <div id="l1-line2">
                <div class="social-icons">
                    <a aria-label="Join us on Facebook" title="Join us on Facebook" href="http://www.facebook.com/mysql"><span class="icon-facebook"></span></a>
                    <a aria-label="Follow us on Twitter" title="Follow us on Twitter" href="https://twitter.com/mysql"><span class="icon-twitter"></span></a>
                    <a aria-label="Follow us on LinkedIn" title="Follow us on LinkedIn" href="https://www.linkedin.com/company/mysql"><span class="icon-linkedin"></span></a>
                    <a aria-label="Visit our YouTube channel" title="Visit our YouTube channel" href="http://www.youtube.com/mysqlchannel"><span class="icon-youtube"></span></a>
                </div>
                <ul id="l1-nav">
                    <li>
                        <a href="https://www.mysql.com/"><!-- <span class="icon-sakila"></span>  -->MySQL.com</a>
                    </li><li>
                        <a href="https://www.mysql.com/downloads/"><!-- <span class="icon-download-thin"></span>  -->Downloads</a>
                    </li><li class="active">
                        <a href="/doc/"><!-- <span class="icon-books"></span>  -->Documentation</a>
                    </li><li>
                        <a href="/"><!-- <span class="icon-code"></span>  -->Developer Zone</a>
                    </li>                </ul>
            </div>
        </div>
        <div id="sub-header">
            <div id="l2-nav-container">
                <div id="l2-nav-toggle">
                    <span class="icon-three-bars"></span>
                </div>
                                                                                        <a class="button nav-button-3" href="/"><span class="icon-code"></span> Developer Zone</a>
                                                                                                                                    <a class="button nav-button-2" href="https://www.mysql.com/downloads/"><span class="icon-download-thin"></span> Downloads</a>
                                                                                                <a class="button nav-button-1" href="https://www.mysql.com/"><span class="icon-sakila"></span> MySQL.com</a>
                                                                        <div id="l2-search-toggle">
                    <span class="icon-search"></span>
                </div>
                <div id="l2-site-icon">
                                                                                                                                                                                                    <span class="icon-books"></span>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        </div>
                <div id="l1-section-title">
                    <span id="l1-section-label">
                        <a href="/doc/">Documentation</a>
                    </span>
                </div>
                <nav>
                    

<ul id="l2-nav">
            	<li class="active"><a class="active " href="/doc/refman/en/">MySQL Server</a>
    			</li>
	        	<li class=""><a  href="/doc/index-enterprise.html">MySQL Enterprise</a>
    			</li>
	        	<li class=""><a  href="/doc/workbench/en/">Workbench</a>
    			</li>
	        	<li class=""><a  href="/doc/en/mysql-innodb-cluster-userguide.html">InnoDB Cluster</a>
    			</li>
	        	<li class=""><a  href="/doc/index-cluster.html">MySQL NDB Cluster</a>
    			</li>
	        	<li class=""><a  href="/doc/index-connectors.html">Connectors</a>
    			</li>
	        	<li class=" last"><a  href="/doc/index-other.html">More</a>
    			</li>
	                        <li class="other-section"><a href="https://www.mysql.com/">MySQL.com</a></li>
                            <li class="other-section"><a href="https://www.mysql.com/downloads/">Downloads</a></li>
                                        <li class="other-section"><a href="/">Developer Zone</a></li>
            </ul>
                </nav>
            </div>
            <div id="l3-search-container"></div>
            <div id="top-orange"><span id="section-nav">Section Menu: &nbsp; </span></div>
        </div>
    </header>
        <div id="page">
                        <div role="main" id="main">

            
                
            
<div>
    <div id="docs-sidebar-toc" class="">
    <div id="docs-toc-inner">
        <div class="docs-sidebar-header" id="docs-nav-header">
            <a class="docs-show-hide-nav" id="docs-hide-nav" href="" title="Hide Sidebar" aria-label="Hide Sidebar"><span class="icon-arrow-small-left"></span></a>
            <div class="docs-nav-links">
                                    
    <a href="fulltext-search-mecab.html"
        aria-label="Previous" title="Previous: MeCab Full-Text Parser Plugin"><span
        class="icon-chevron-left"></span></a>
<a href="index.html" aria-label="Start" title="Start"><span class="icon-book-open"></span></a>
        <a aria-label="Up" href="functions.html" title="Up: Functions and Operators"><span class="icon-chevron-up"></span></a>
    <a href="xml-functions.html" aria-label="Next"
        title="Next: XML Functions"><span
        class="icon-chevron-right"></span></a>
                            </div>
        </div>
                    
<div id="docs-sidebar-search-container">
    <div id="docs-sidebar-search-box">
        <form method="get" action="/mysql-manual/search-page">
            <input type="hidden" name="d" id="d" value="201" />
            <input type="hidden" name="p" id="p" value="1" />
            <input type="text" name="keyword" id="q" title="Search this Manual"
                value=""
                style="color: #bbb;"
                onfocus=""
                onblur="" />

            <button class="docs-sidebar-search-btn" aria-label="Search" title="Search" type="submit">
                <span class="icon-search"></span>
            </button>
        </form>
    </div>
</div>
                <div class="docs-sidebar-nav">
            <a class="docs-icon-home" href="/doc/"><span class="icon-home"></span>Documentation Home</a><hr />
            <div class="docs-sidebar-mtitle">MySQL 8.0 Reference Manual</div>
            <nav class="doctoc" id="doc-201">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="preface.html">Preface and Legal Notices</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="introduction.html">General Information</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="installing.html">Installing and Upgrading MySQL</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="tutorial.html">Tutorial</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="programs.html">MySQL Programs</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="server-administration.html">MySQL Server Administration</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="security.html">Security</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="backup-and-recovery.html">Backup and Recovery</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="optimization.html">Optimization</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="language-structure.html">Language Structure</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="charset.html">Character Sets, Collations, Unicode</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="data-types.html">Data Types</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-down"></span></a></div><div class="docs-sidebar-nav-link"><a href="functions.html">Functions and Operators</a></div></div>                        <div class="docs-submenu">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="func-op-summary-ref.html">Function and Operator Reference</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="type-conversion.html">Type Conversion in Expression Evaluation</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="non-typed-operators.html">Operators</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="operator-precedence.html">Operator Precedence</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="comparison-operators.html">Comparison Functions and Operators</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="logical-operators.html">Logical Operators</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="assignment-operators.html">Assignment Operators</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="control-flow-functions.html">Control Flow Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="string-functions.html">String Functions</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="string-comparison-functions.html">String Comparison Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="regexp.html">Regular Expressions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="string-functions-charset.html">Character Set and Collation of Function Results</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="numeric-functions.html">Numeric Functions and Operators</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="arithmetic-functions.html">Arithmetic Operators</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="mathematical-functions.html">Mathematical Functions</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="date-and-time-functions.html">Date and Time Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="mysql-calendar.html">What Calendar Is Used By MySQL?</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="fulltext-search.html">Full-Text Search Functions</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="fulltext-natural-language.html">Natural Language Full-Text Searches</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="fulltext-boolean.html">Boolean Full-Text Searches</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="fulltext-query-expansion.html">Full-Text Searches with Query Expansion</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="fulltext-stopwords.html">Full-Text Stopwords</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="fulltext-restrictions.html">Full-Text Restrictions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="fulltext-fine-tuning.html">Fine-Tuning MySQL Full-Text Search</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="full-text-adding-collation.html">Adding a Collation for Full-Text Indexing</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="fulltext-search-ngram.html">ngram Full-Text Parser</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="fulltext-search-mecab.html">MeCab Full-Text Parser Plugin</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link current"><a href="cast-functions.html">Cast Functions and Operators</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="xml-functions.html">XML Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="bit-functions.html">Bit Functions and Operators</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="encryption-functions.html">Encryption and Compression Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="locking-functions.html">Locking Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="information-functions.html">Information Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="spatial-analysis-functions.html">Spatial Analysis Functions</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="spatial-function-reference.html">Spatial Function Reference</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="spatial-function-argument-handling.html">Argument Handling by Spatial Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gis-wkt-functions.html">Functions That Create Geometry Values from WKT Values</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gis-wkb-functions.html">Functions That Create Geometry Values from WKB Values</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gis-mysql-specific-functions.html">MySQL-Specific Functions That Create Geometry Values</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gis-format-conversion-functions.html">Geometry Format Conversion Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="gis-property-functions.html">Geometry Property Functions</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gis-general-property-functions.html">General Geometry Property Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gis-point-property-functions.html">Point Property Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gis-linestring-property-functions.html">LineString and MultiLineString Property Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gis-polygon-property-functions.html">Polygon and MultiPolygon Property Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gis-geometrycollection-property-functions.html">GeometryCollection Property Functions</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="spatial-operator-functions.html">Spatial Operator Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="spatial-relation-functions.html">Functions That Test Spatial Relations Between Geometry Objects</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="spatial-relation-functions-object-shapes.html">Spatial Relation Functions That Use Object Shapes</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="spatial-relation-functions-mbr.html">Spatial Relation Functions That Use Minimum Bounding Rectangles</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="spatial-geohash-functions.html">Spatial Geohash Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="spatial-geojson-functions.html">Spatial GeoJSON Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="spatial-convenience-functions.html">Spatial Convenience Functions</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="json-functions.html">JSON Functions</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="json-function-reference.html">JSON Function Reference</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="json-creation-functions.html">Functions That Create JSON Values</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="json-search-functions.html">Functions That Search JSON Values</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="json-modification-functions.html">Functions That Modify JSON Values</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="json-attribute-functions.html">Functions That Return JSON Value Attributes</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="json-table-functions.html">JSON Table Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="json-validation-functions.html">JSON Schema Validation Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="json-utility-functions.html">JSON Utility Functions</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="gtid-functions.html">Functions Used with Global Transaction Identifiers (GTIDs)</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="enterprise-encryption.html">MySQL Enterprise Encryption Functions</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="enterprise-encryption-installation.html">MySQL Enterprise Encryption Installation</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="enterprise-encryption-usage.html">MySQL Enterprise Encryption Usage and Examples</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="enterprise-encryption-function-reference.html">MySQL Enterprise Encryption Function Reference</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="enterprise-encryption-functions.html">MySQL Enterprise Encryption Function Descriptions</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="group-by-functions-and-modifiers.html">Aggregate (GROUP BY) Functions</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="group-by-functions.html">Aggregate (GROUP BY) Function Descriptions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="group-by-modifiers.html">GROUP BY Modifiers</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="group-by-handling.html">MySQL Handling of GROUP BY</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="group-by-functional-dependence.html">Detection of Functional Dependence</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="window-functions.html">Window Functions</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="window-function-descriptions.html">Window Function Descriptions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="window-functions-usage.html">Window Function Concepts and Syntax</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="window-functions-frames.html">Window Function Frame Specification</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="window-functions-named-windows.html">Named Windows</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="window-function-restrictions.html">Window Function Restrictions</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="performance-schema-functions.html">Performance Schema Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="internal-functions.html">Internal Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="miscellaneous-functions.html">Miscellaneous Functions</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable  loaded" aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="precision-math.html">Precision Math</a></div></div>                        <div class="docs-submenu hidden">
                                    
    <ul>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="precision-math-numbers.html">Types of Numeric Values</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="precision-math-decimal-characteristics.html">DECIMAL Data Type Characteristics</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="precision-math-expressions.html">Expression Handling</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="precision-math-rounding.html">Rounding Behavior</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="precision-math-examples.html">Precision Math Examples</a></div></div>                    </li>
        </ul>
                            </div>
                    </li>
        </ul>
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="sql-syntax.html">SQL Statement Syntax</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="data-dictionary.html">MySQL Data Dictionary</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="innodb-storage-engine.html">The InnoDB Storage Engine</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="storage-engines.html">Alternative Storage Engines</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="replication.html">Replication</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="group-replication.html">Group Replication</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="mysql-shell-userguide.html">MySQL Shell</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="document-store.html">Using MySQL as a Document Store</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="mysql-innodb-cluster-userguide.html">InnoDB Cluster</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="mysql-cluster.html">MySQL NDB Cluster 8.0</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="partitioning.html">Partitioning</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="stored-objects.html">Stored Objects</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="information-schema.html">INFORMATION_SCHEMA Tables</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="performance-schema.html">MySQL Performance Schema</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="sys-schema.html">MySQL sys Schema</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="connectors-apis.html">Connectors and APIs</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="extending-mysql.html">Extending MySQL</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="mysql-enterprise.html">MySQL Enterprise Edition</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="workbench.html">MySQL Workbench</a></div></div>                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="faqs.html">MySQL 8.0 Frequently Asked Questions</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="error-handling.html">Errors, Error Codes, and Common Problems</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="restrictions.html">Restrictions and Limits</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><a class="expandable " aria-label="Subnav" href=""><span class="icon-chevron-right"></span></a></div><div class="docs-sidebar-nav-link"><a href="indexes.html">Indexes</a></div></div>                        <div class="docs-submenu hidden">
                            </div>
                    </li>
            <li>
            <div><div class="docs-sidebar-nav-icon"><span class="icon-dot"></span></div><div class="docs-sidebar-nav-link"><a href="glossary.html">MySQL Glossary</a></div></div>                    </li>
        </ul>
                            </nav>
        </div>

        
<a class="docs-sidebar-section" href=""><span class="icon-related"></span>
    <span class="text">Related Documentation</span></a>
<div class="docs-sidebar-accordian open">
    <div class="text">
        <a href="/doc/relnotes/mysql/8.0/en/">MySQL 8.0 Release Notes</a><br />
        <a href="/doc/dev/mysql-server/latest/">MySQL 8.0 Source Code Documentation</a><br />
        </div>
</div>

    <a class="docs-sidebar-section" href=""><span class="icon-download-thin"></span>
        <span class="text">
            Download
                            this Manual
                    </span>
    </a>
    <div class="docs-sidebar-accordian open">
        <div class="text">
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.pdf">PDF (US Ltr)</a>
            - 46.1Mb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.a4.pdf">PDF (A4)</a>
            - 46.1Mb<br />
                        <a href="https://downloads.mysql.com/docs/mysql-ref-manual-8.0-en-pdf-1-20190611.noarch.rpm">PDF (RPM)</a>
            - 41.5Mb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.html-chapter.tar.gz">HTML Download (TGZ)</a>
            - 10.6Mb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.html-chapter.zip">HTML Download (Zip)</a>
            - 10.6Mb<br />
                        <a href="https://downloads.mysql.com/docs/mysql-ref-manual-8.0-en-html-chapter-1-20190611.noarch.rpm">HTML Download (RPM)</a>
            - 9.1Mb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.man-gpl.tar.gz">Man Pages (TGZ)</a>
            - 220.4Kb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.man-gpl.zip">Man Pages (Zip)</a>
            - 325.8Kb<br />
                        <a href="https://downloads.mysql.com/docs/mysql-8.0.info.gz">Info (Gzip)</a>
            - 4.1Mb<br />
                        <a href="https://downloads.mysql.com/docs/mysql-8.0.info.zip">Info (Zip)</a>
            - 4.1Mb<br />
                    </div>
    </div>

<a class="docs-sidebar-section" href=""><span class="icon-book"></span>
    <span class="text">Excerpts from this Manual</span></a>
<div class="docs-sidebar-accordian">
    <div class="text">
                <a href="/doc/mysql-backup-excerpt/8.0/en/">MySQL Backup and Recovery</a><br />
                <a href="/doc/mysql-g11n-excerpt/8.0/en/">MySQL Globalization</a><br />
                <a href="/doc/mysql-infoschema-excerpt/8.0/en/">MySQL Information Schema</a><br />
                <a href="/doc/mysql-installation-excerpt/8.0/en/">MySQL Installation Guide</a><br />
                <a href="/doc/mysql-security-excerpt/8.0/en/">Security in MySQL</a><br />
                <a href="/doc/mysql-startstop-excerpt/8.0/en/">Starting and Stopping MySQL</a><br />
                <a href="/doc/mysql-linuxunix-excerpt/8.0/en/">MySQL and Linux/Unix</a><br />
                <a href="/doc/mysql-windows-excerpt/8.0/en/">MySQL and Windows</a><br />
                <a href="/doc/mysql-osx-excerpt/8.0/en/">MySQL and OS X</a><br />
                <a href="/doc/mysql-solaris-excerpt/8.0/en/">MySQL and Solaris</a><br />
                <a href="/doc/mysql-sourcebuild-excerpt/8.0/en/">Building MySQL from Source</a><br />
                <a href="/doc/mysql-reslimits-excerpt/8.0/en/">MySQL Restrictions and Limitations</a><br />
                <a href="/doc/mysql-partitioning-excerpt/8.0/en/">MySQL Partitioning</a><br />
                <a href="/doc/mysql-secure-deployment-guide/8.0/en/">MySQL Secure Deployment Guide</a><br />
                <a href="/doc/mysql-tutorial-excerpt/8.0/en/">MySQL Tutorial</a><br />
                <a href="/doc/mysql-perfschema-excerpt/8.0/en/">MySQL Performance Schema</a><br />
                <a href="/doc/mysql-replication-excerpt/8.0/en/">MySQL Replication</a><br />
                <a href="/doc/mysql-repo-excerpt/8.0/en/">Using the MySQL Yum Repository</a><br />
            </div>
</div>

        <br /><span id="wkr"><br /></span>
    </div>
    </div>

    <div id="docs-main" class="has-toc">
    <div id="docs-main-inner">

                <div class="right" id="docs-version-nav">
            <a href="" id="docs-version-nav-toggle">version 8.0
            <span class="icon-chevron-down"></span></a>
            <div id="docs-version-list">
                                                                                            <a                         href="/doc/refman/5.7/en/cast-functions.html">
                        5.7
                                            </a><br />
                                                                            <a                         href="/doc/refman/5.6/en/cast-functions.html">
                        5.6
                                            </a><br />
                                                                            <a                         href="/doc/refman/5.5/en/cast-functions.html">
                        5.5
                                            </a><br />
                                                                        <div id="docs-version-nav-lang">
                                                                                                                                                    <a                                     href="/doc/refman/5.6/ja/cast-functions.html">
                                    5.6&nbsp;
                                                                            Japanese
                                                                    </a><br />
                                                                                            </div>
                            </div>
        </div>
        
        <div id="docs-show-nav" class="left hidden" style="margin-right: 15px;">
            <a class="docs-show-hide-nav" href="" aria-label="Show Sidebar"
                title="Show Sidebar"><span class="icon-arrow-small-right"></span></a>
        </div>

                        <div id="docs-breadcrumbs">
            <a href="/doc/refman/8.0/en/">MySQL 8.0 Reference Manual</a> &nbsp;/&nbsp;
                                                        <a href="functions.html">Functions and Operators</a> &nbsp;/&nbsp;
                                                                                    Cast Functions and Operators
                                    </div>
        
        <div id="docs-body">
        
<div class="section">

<div class="titlepage">
<div>
<div>
<h2 class="title"><a name="cast-functions"></a>12.10 Cast Functions and Operators</h2>

</div>

</div>

</div>
<a class="indexterm" name="idm139663189255600"></a><a class="indexterm" name="idm139663189254560"></a><a class="indexterm" name="idm139663189253488"></a><a class="indexterm" name="idm139663189252000"></a><a class="indexterm" name="idm139663189250928"></a>
<div class="table">
<a name="idm139663189249440"></a><p class="title"><b>Table 12.14 Cast Functions and Operators</b></p>
<div class="table-contents">
<table frame="box" rules="all" summary="A reference that lists cast functions and operators."><col width="40%"><col width="60%"><thead><tr><th scope="col">Name</th>
<th scope="col">Description</th>
</tr></thead><tbody><tr><td scope="row"><a class="link" href="cast-functions.html#operator_binary"><code class="literal">BINARY</code></a></td>
<td>
      Cast a string to a binary string
    </td>
</tr><tr><td scope="row"><a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a></td>
<td>
      Cast a value as a certain type
    </td>
</tr><tr><td scope="row"><a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a></td>
<td>
      Cast a value as a certain type
    </td>
</tr></tbody></table>
</div>

</div>
<br class="table-break"><p>
      Cast functions and operators enable conversion of values from one
      data type to another.
    </p><p>
      <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> with a
      <code class="literal">USING</code> clause provides a way to convert data
      between different character sets:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql one-line"><code class="language-sql">CONVERT(<em class="replaceable">expr</em> USING <em class="replaceable">transcoding_name</em>)</code></pre><p>
      In MySQL, transcoding names are the same as the corresponding
      character set names.
    </p><p>
      Examples:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">SELECT CONVERT(_latin1'Müller' USING utf8);
INSERT INTO utf8_table (utf8_column)
    SELECT CONVERT(latin1_column USING utf8) FROM latin1_table;</code></pre><p>
      You can also use <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> without
      <code class="literal">USING</code> or <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a>
      to convert strings between different character sets:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">CONVERT(<em class="replaceable">string</em>, CHAR[(<em class="replaceable">N</em>)] CHARACTER SET <em class="replaceable">charset_name</em>)
CAST(<em class="replaceable">string</em> AS CHAR[(<em class="replaceable">N</em>)] CHARACTER SET <em class="replaceable">charset_name</em>)</code></pre><p>
      Examples:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">SELECT CONVERT('test', CHAR CHARACTER SET utf8);
SELECT CAST('test' AS CHAR CHARACTER SET utf8);</code></pre><p>
      If you specify <code class="literal">CHARACTER SET
      <em class="replaceable"><code>charset_name</code></em></code> as just shown,
      the resulting character set and collation are
      <em class="replaceable"><code>charset_name</code></em> and the default collation
      of <em class="replaceable"><code>charset_name</code></em>. If you omit
      <code class="literal">CHARACTER SET
      <em class="replaceable"><code>charset_name</code></em></code>, the resulting
      character set and collation are defined by the
      <a class="link" href="server-system-variables.html#sysvar_character_set_connection"><code class="literal">character_set_connection</code></a> and
      <a class="link" href="server-system-variables.html#sysvar_collation_connection"><code class="literal">collation_connection</code></a> system
      variables that determine the default connection character set and
      collation (see <a class="xref" href="charset-connection.html" title="10.4 Connection Character Sets and Collations">Section 10.4, “Connection Character Sets and Collations”</a>).
    </p><p>
      A <code class="literal">COLLATE</code> clause is not permitted within a
      <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> or
      <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a> call, but you can apply it
      to the function result. For example, this is legal:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql one-line"><code class="language-sql">SELECT CAST('test' AS CHAR CHARACTER SET utf8) COLLATE utf8_bin;</code></pre><p>
      But this is illegal:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql one-line"><code class="language-sql">SELECT CAST('test' AS CHAR CHARACTER SET utf8 COLLATE utf8_bin);</code></pre><p>
      Normally, you cannot compare a <a class="link" href="blob.html" title="11.4.3 The BLOB and TEXT Types"><code class="literal">BLOB</code></a>
      value or other binary string in case-insensitive fashion because
      binary strings use the <code class="literal">binary</code> character set,
      which has no collation with the concept of lettercase. To perform
      a case-insensitive comparison, use the
      <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> or
      <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a> function to convert the
      value to a nonbinary string. Comparisons of the resulting string
      use its collation. For example, if the conversion result character
      set has a case-insensitive collation, a
      <a class="link" href="string-comparison-functions.html#operator_like"><code class="literal">LIKE</code></a> operation is not case-sensitive:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">SELECT 'A' LIKE CONVERT(<em class="replaceable">blob_col</em> USING latin1)
  FROM <em class="replaceable">tbl_name</em>;</code></pre><p>
      To use a different character set, substitute its name for
      <code class="literal">latin1</code> in the preceding statement. To specify a
      particular collation for the converted string, use a
      <code class="literal">COLLATE</code> clause following the
      <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> call:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">SELECT 'A' LIKE CONVERT(<em class="replaceable">blob_col</em> USING latin1) COLLATE latin1_german1_ci
  FROM <em class="replaceable">tbl_name</em>;</code></pre><p>
      <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> and
      <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a> can be used more generally
      for comparing strings that are represented in different character
      sets. For example, a comparison of these strings results in an
      error because they have different character sets:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SET @s1 = _latin1 'abc', @s2 = _latin2 'abc';
mysql&gt; SELECT @s1 = @s2;
ERROR 1267 (HY000): Illegal mix of collations (latin1_swedish_ci,IMPLICIT)
and (latin2_general_ci,IMPLICIT) for operation '='</code></pre><p>
      Converting one of the strings to a character set compatible with
      the other enables the comparison to occur without error:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SELECT @s1 = CONVERT(@s2 USING latin1);
+---------------------------------+
| @s1 = CONVERT(@s2 USING latin1) |
+---------------------------------+
|                               1 |
+---------------------------------+</code></pre><p>
      For string literals, another way to specify the character set is
      to use a character set introducer (<code class="literal">_latin1</code> and
      <code class="literal">_latin2</code> in the preceding example are instances
      of introducers). Unlike conversion functions such as
      <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a>, or
      <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a>, which convert a string
      from one character set to another, an introducer designates a
      string literal as having a particular character set, with no
      conversion involved. For more information, see
      <a class="xref" href="charset-introducer.html" title="10.3.8 Character Set Introducers">Section 10.3.8, “Character Set Introducers”</a>.
    </p><p>
      Character set conversion is also useful preceding lettercase
      conversion of binary strings.
      <a class="link" href="string-functions.html#function_lower"><code class="literal">LOWER()</code></a> and
      <a class="link" href="string-functions.html#function_upper"><code class="literal">UPPER()</code></a> are ineffective when
      applied directly to binary strings because the concept of
      lettercase does not apply. To perform lettercase conversion of a
      binary string, first convert it to a nonbinary string:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SET @str = BINARY 'New York';
mysql&gt; SELECT LOWER(@str), LOWER(CONVERT(@str USING utf8mb4));
+-------------+------------------------------------+
| LOWER(@str) | LOWER(CONVERT(@str USING utf8mb4)) |
+-------------+------------------------------------+
| New York    | new york                           |
+-------------+------------------------------------+</code></pre><p>
      If you convert an indexed column using
      <a class="link" href="cast-functions.html#operator_binary"><code class="literal">BINARY</code></a>,
      <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a>, or
      <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a>, MySQL may not be able to
      use the index efficiently.
    </p><p>
      The cast functions are useful for creating a column with a
      specific type in a
      <a class="link" href="create-table.html" title="13.1.20 CREATE TABLE Syntax"><code class="literal">CREATE TABLE ...
      SELECT</code></a> statement:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; CREATE TABLE new_table SELECT CAST('2000-01-01' AS DATE) AS c1;
mysql&gt; SHOW CREATE TABLE new_table\G
*************************** 1. row ***************************
       Table: new_table
Create Table: CREATE TABLE `new_table` (
  `c1` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4</code></pre><p>
      The cast functions are useful for sorting
      <a class="link" href="enum.html" title="11.4.4 The ENUM Type"><code class="literal">ENUM</code></a> columns in lexical order.
      Normally, sorting of <a class="link" href="enum.html" title="11.4.4 The ENUM Type"><code class="literal">ENUM</code></a> columns
      occurs using the internal numeric values. Casting the values to
      <a class="link" href="char.html" title="11.4.1 The CHAR and VARCHAR Types"><code class="literal">CHAR</code></a> results in a lexical sort:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql one-line"><code class="language-sql">SELECT <em class="replaceable">enum_col</em> FROM <em class="replaceable">tbl_name</em> ORDER BY CAST(<em class="replaceable">enum_col</em> AS CHAR);</code></pre><p>
      <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a> also changes the result if
      you use it as part of a more complex expression such as
      <a class="link" href="string-functions.html#function_concat"><code class="literal">CONCAT('Date: ',CAST(NOW() AS
      DATE))</code></a>.
    </p><p>
      For temporal values, there is little need to use
      <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a> to extract data in different
      formats. Instead, use a function such as
      <a class="link" href="date-and-time-functions.html#function_extract"><code class="literal">EXTRACT()</code></a>,
      <a class="link" href="date-and-time-functions.html#function_date-format"><code class="literal">DATE_FORMAT()</code></a>, or
      <a class="link" href="date-and-time-functions.html#function_time-format"><code class="literal">TIME_FORMAT()</code></a>. See
      <a class="xref" href="date-and-time-functions.html" title="12.7 Date and Time Functions">Section 12.7, “Date and Time Functions”</a>.
    </p><p>
      To cast a string to a number, you normally need do nothing other
      than use the string value in numeric context:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SELECT 1+'1';
       -&gt; 2</code></pre><p>
      That is also true for hexadecimal and bit literals, which are
      binary strings by default:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SELECT X'41', X'41'+0;
        -&gt; 'A', 65
mysql&gt; SELECT b'1100001', b'1100001'+0;
        -&gt; 'a', 97</code></pre><p>
      A string used in an arithmetic operation is converted to a
      floating-point number during expression evaluation.
    </p><p>
      A number used in string context is converted to a string:
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SELECT CONCAT('hello you ',2);
        -&gt; 'hello you 2'</code></pre><p>
      For information about implicit conversion of numbers to strings,
      see <a class="xref" href="type-conversion.html" title="12.2 Type Conversion in Expression Evaluation">Section 12.2, “Type Conversion in Expression Evaluation”</a>.
    </p><p>
      MySQL supports arithmetic with both signed and unsigned 64-bit
      values. For numeric operators (such as
      <a class="link" href="arithmetic-functions.html#operator_plus"><code class="literal">+</code></a> or
      <a class="link" href="arithmetic-functions.html#operator_minus"><code class="literal">-</code></a>) where one of the
      operands is an unsigned integer, the result is unsigned by default
      (see <a class="xref" href="arithmetic-functions.html" title="12.6.1 Arithmetic Operators">Section 12.6.1, “Arithmetic Operators”</a>). To override this,
      use the <code class="literal">SIGNED</code> or <code class="literal">UNSIGNED</code>
      cast operator to cast a value to a signed or unsigned 64-bit
      integer, respectively.
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SELECT 1 - 2;
        -&gt; -1
mysql&gt; SELECT CAST(1 - 2 AS UNSIGNED);
        -&gt; 18446744073709551615
mysql&gt; SELECT CAST(CAST(1 - 2 AS UNSIGNED) AS SIGNED);
        -&gt; -1</code></pre><p>
      If either operand is a floating-point value, the result is a
      floating-point value and is not affected by the preceding rule.
      (In this context, <a class="link" href="fixed-point-types.html" title="11.2.2 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC"><code class="literal">DECIMAL</code></a> column
      values are regarded as floating-point values.)
    </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SELECT CAST(1 AS UNSIGNED) - 2.0;
        -&gt; -1.0</code></pre><p>
      The SQL mode affects the result of conversion operations (see
      <a class="xref" href="sql-mode.html" title="5.1.11 Server SQL Modes">Section 5.1.11, “Server SQL Modes”</a>). Examples:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
          For conversion of a <span class="quote">“<span class="quote">zero</span>”</span> date string to a date,
          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> and
          <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a> return
          <code class="literal">NULL</code> and produce a warning when the
          <a class="link" href="sql-mode.html#sqlmode_no_zero_date"><code class="literal">NO_ZERO_DATE</code></a> SQL mode is
          enabled.
        </p></li><li class="listitem"><p>
          For integer subtraction, if the
          <a class="link" href="sql-mode.html#sqlmode_no_unsigned_subtraction"><code class="literal">NO_UNSIGNED_SUBTRACTION</code></a> SQL
          mode is enabled, the subtraction result is signed even if any
          operand is unsigned.
</p></li></ul>
</div>
<p>
      The following list describes the available cast functions and
      operators:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><a name="operator_binary"></a><p>
          <a class="indexterm" name="idm139663189114832"></a>

          <a class="link" href="cast-functions.html#operator_binary"><code class="literal">BINARY</code></a>
          <em class="replaceable"><code>expr</code></em>
        </p><p>
          The <a class="link" href="cast-functions.html#operator_binary"><code class="literal">BINARY</code></a> operator converts the
          expression to a binary string. A common use for
          <a class="link" href="cast-functions.html#operator_binary"><code class="literal">BINARY</code></a> is to force a character
          string comparison to be done byte by byte rather than
          character by character, in effect becoming case-sensitive. The
          <a class="link" href="cast-functions.html#operator_binary"><code class="literal">BINARY</code></a> operator also causes
          trailing spaces in comparisons to be significant.
        </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SELECT 'a' = 'A';
        -&gt; 1
mysql&gt; SELECT BINARY 'a' = 'A';
        -&gt; 0
mysql&gt; SELECT 'a' = 'a ';
        -&gt; 1
mysql&gt; SELECT BINARY 'a' = 'a ';
        -&gt; 0</code></pre><p>
          In a comparison, <a class="link" href="cast-functions.html#operator_binary"><code class="literal">BINARY</code></a> affects
          the entire operation; it can be given before either operand
          with the same result.
        </p><p>
          For purposes of converting a string expression to a binary
          string, these constructs are equivalent:
        </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">BINARY <em class="replaceable">expr</em>
CAST(<em class="replaceable">expr</em> AS BINARY)
CONVERT(<em class="replaceable">expr</em> USING BINARY)</code></pre><p>
          If a value is a string literal, it can be designated as a
          binary string without performing any conversion by using the
          <code class="literal">_binary</code> character set introducer:
        </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">mysql&gt; SELECT 'a' = 'A';
        -&gt; 1
mysql&gt; SELECT _binary 'a' = 'A';
        -&gt; 0</code></pre><p>
          For information about introducers, see
          <a class="xref" href="charset-introducer.html" title="10.3.8 Character Set Introducers">Section 10.3.8, “Character Set Introducers”</a>.
        </p><p>
          The <a class="link" href="cast-functions.html#operator_binary"><code class="literal">BINARY</code></a> operator in
          expressions differs in effect from the
          <code class="literal">BINARY</code> attribute in character column
          definitions. A character column defined with the
          <code class="literal">BINARY</code> attribute is assigned table default
          character set and the binary (<code class="literal">_bin</code>)
          collation of that character set. Every nonbinary character set
          has a <code class="literal">_bin</code> collation. For example, the
          binary collation for the <code class="literal">utf8</code> character set
          is <code class="literal">utf8_bin</code>, so if the table default
          character set is <code class="literal">utf8</code>, these two column
          definitions are equivalent:
        </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">CHAR(10) BINARY
CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin</code></pre><p>
          The use of <code class="literal">CHARACTER SET binary</code> in the
          definition of a <a class="link" href="char.html" title="11.4.1 The CHAR and VARCHAR Types"><code class="literal">CHAR</code></a>,
          <a class="link" href="char.html" title="11.4.1 The CHAR and VARCHAR Types"><code class="literal">VARCHAR</code></a>, or
          <a class="link" href="blob.html" title="11.4.3 The BLOB and TEXT Types"><code class="literal">TEXT</code></a> column causes the column
          to be treated as the corresponding binary string data type.
          For example, the following pairs of definitions are
          equivalent:
        </p><pre class="programlisting copytoclipboard line-numbers language-sql"><code class="language-sql">CHAR(10) CHARACTER SET binary
BINARY(10)

VARCHAR(10) CHARACTER SET binary
VARBINARY(10)

TEXT CHARACTER SET binary
BLOB</code></pre></li><li class="listitem"><a name="function_cast"></a><p>
          <a class="indexterm" name="idm139663189075120"></a>

          <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST(<em class="replaceable"><code>expr</code></em> AS
          <em class="replaceable"><code>type</code></em>)</code></a>
        </p><p>
          The <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a> function takes an
          expression of any type and produces a result value of the
          specified type, similar to
          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a>. For more
          information, see the description of
          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a>.
        </p><p>
          <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a> is standard SQL syntax.
        </p></li><li class="listitem"><a name="function_convert"></a><p>
          <a class="indexterm" name="idm139663189061184"></a>

          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT(<em class="replaceable"><code>expr</code></em>,<em class="replaceable"><code>type</code></em>)</code></a>,
          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT(<em class="replaceable"><code>expr</code></em>
          USING <em class="replaceable"><code>transcoding_name</code></em>)</code></a>
        </p><p>
          The <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> function takes an
          expression of any type and produces a result value of the
          specified type.
        </p><p>
          Discussion of
          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT(<em class="replaceable"><code>expr</code></em>,
          <em class="replaceable"><code>type</code></em>)</code></a> syntax here also
          applies to
          <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST(<em class="replaceable"><code>expr</code></em> AS
          <em class="replaceable"><code>type</code></em>)</code></a>, which is
          equivalent.
        </p><p>
          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT(... USING ...)</code></a> is
          standard SQL syntax. The non-<code class="literal">USING</code> form of
          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> is ODBC syntax.
        </p><p>
          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> with
          <code class="literal">USING</code> converts data between different
          character sets. In MySQL, transcoding names are the same as
          the corresponding character set names. For example, this
          statement converts the string <code class="literal">'abc'</code> in the
          default character set to the corresponding string in the
          <code class="literal">utf8</code> character set:
        </p><pre class="programlisting copytoclipboard line-numbers language-sql one-line"><code class="language-sql">SELECT CONVERT('abc' USING utf8);</code></pre><p>
          <a class="link" href="cast-functions.html#function_convert"><code class="literal">CONVERT()</code></a> without
          <code class="literal">USING</code> and
          <a class="link" href="cast-functions.html#function_cast"><code class="literal">CAST()</code></a> take an expression and a
          <em class="replaceable"><code>type</code></em> value specifying the result
          type. These <em class="replaceable"><code>type</code></em> values are
          permitted:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
              <code class="literal">BINARY[(<em class="replaceable"><code>N</code></em>)]</code>
            </p><p>
              Produces a string with the
              <a class="link" href="binary-varbinary.html" title="11.4.2 The BINARY and VARBINARY Types"><code class="literal">BINARY</code></a> data type. See
              <a class="xref" href="binary-varbinary.html" title="11.4.2 The BINARY and VARBINARY Types">Section 11.4.2, “The BINARY and VARBINARY Types”</a> for a description of
              how this affects comparisons. If the optional length
              <em class="replaceable"><code>N</code></em> is given,
              <code class="literal">BINARY(<em class="replaceable"><code>N</code></em>)</code>
              causes the cast to use no more than
              <em class="replaceable"><code>N</code></em> bytes of the argument. Values
              shorter than <em class="replaceable"><code>N</code></em> bytes are padded
              with <code class="literal">0x00</code> bytes to a length of
              <em class="replaceable"><code>N</code></em>.
            </p></li><li class="listitem"><p>
              <code class="literal">CHAR[(<em class="replaceable"><code>N</code></em>)]
              [<em class="replaceable"><code>charset_info</code></em>]</code>
            </p><p>
              Produces a string with the
              <a class="link" href="char.html" title="11.4.1 The CHAR and VARCHAR Types"><code class="literal">CHAR</code></a> data type. If the
              optional length <em class="replaceable"><code>N</code></em> is given,
              <code class="literal">CHAR(<em class="replaceable"><code>N</code></em>)</code>
              causes the cast to use no more than
              <em class="replaceable"><code>N</code></em> characters of the argument.
              No padding occurs for values shorter than
              <em class="replaceable"><code>N</code></em> characters.
            </p><p>
              With no <em class="replaceable"><code>charset_info</code></em> clause,
              <code class="literal">CHAR</code> produces a string with the default
              character set. To specify the character set explicitly,
              these <em class="replaceable"><code>charset_info</code></em> values are
              permitted:
</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: square; "><li class="listitem"><p>
                  <code class="literal">CHARACTER SET
                  <em class="replaceable"><code>charset_name</code></em></code>:
                  Produces a string with the given character set.
                </p></li><li class="listitem"><p>
                  <code class="literal">ASCII</code>: Shorthand for
                  <code class="literal">CHARACTER SET latin1</code>.
                </p></li><li class="listitem"><p>
                  <code class="literal">UNICODE</code>: Shorthand for
                  <code class="literal">CHARACTER SET ucs2</code>.
</p></li></ul>
</div>
<p>
              In all cases, the string has the default collation for the
              character set.
            </p></li><li class="listitem"><p>
              <code class="literal">DATE</code>
            </p><p>
              Produces a <a class="link" href="datetime.html" title="11.3.1 The DATE, DATETIME, and TIMESTAMP Types"><code class="literal">DATE</code></a> value.
            </p></li><li class="listitem"><p>
              <code class="literal">DATETIME</code>
            </p><p>
              Produces a <a class="link" href="datetime.html" title="11.3.1 The DATE, DATETIME, and TIMESTAMP Types"><code class="literal">DATETIME</code></a> value.
            </p></li><li class="listitem"><p>
              <code class="literal">DECIMAL[(<em class="replaceable"><code>M</code></em>[,<em class="replaceable"><code>D</code></em>])]</code>
            </p><p>
              Produces a <a class="link" href="fixed-point-types.html" title="11.2.2 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC"><code class="literal">DECIMAL</code></a> value.
              If the optional <em class="replaceable"><code>M</code></em> and
              <em class="replaceable"><code>D</code></em> values are given, they
              specify the maximum number of digits (the precision) and
              the number of digits following the decimal point (the
              scale).
            </p></li><li class="listitem"><p>
              <code class="literal">DOUBLE</code>
            </p><p>
              Produces a <a class="link" href="floating-point-types.html" title="11.2.3 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE"><code class="literal">DOUBLE</code></a> result.
              Added in MySQL 8.0.17.
            </p></li><li class="listitem"><p>
              FLOAT[(<em class="replaceable"><code>P</code></em>)]
            </p><p>
              If the precision <em class="replaceable"><code>P</code></em> is not
              specified, produces a result of type
              <a class="link" href="floating-point-types.html" title="11.2.3 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE"><code class="literal">FLOAT</code></a>. If
              <em class="replaceable"><code>P</code></em> is provided and 0 &lt;= &lt;
              <em class="replaceable"><code>P</code></em> &lt;= 24, the result is of
              type <code class="literal">FLOAT</code>. If 25 &lt;=
              <em class="replaceable"><code>P</code></em> &lt;= 53, the result is of
              type <a class="link" href="floating-point-types.html" title="11.2.3 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE"><code class="literal">REAL</code></a>. If
              <em class="replaceable"><code>P</code></em> &lt; 0 or
              <em class="replaceable"><code>P</code></em> &gt; 53, an error is
              returned. Added in MySQL 8.0.17.
            </p></li><li class="listitem"><p>
              <code class="literal">JSON</code>
            </p><p>
              Produces a <a class="link" href="json.html" title="11.6 The JSON Data Type"><code class="literal">JSON</code></a> value. For
              details on the rules for conversion of values between
              <a class="link" href="json.html" title="11.6 The JSON Data Type"><code class="literal">JSON</code></a> and other types, see
              <a class="xref" href="json.html#json-comparison" title="Comparison and Ordering of JSON Values">Comparison and Ordering of JSON Values</a>.
            </p></li><li class="listitem"><p>
              <code class="literal">NCHAR[(<em class="replaceable"><code>N</code></em>)]</code>
            </p><p>
              Like <code class="literal">CHAR</code>, but produces a string with
              the national character set. See
              <a class="xref" href="charset-national.html" title="10.3.7 The National Character Set">Section 10.3.7, “The National Character Set”</a>.
            </p><p>
              Unlike <code class="literal">CHAR</code>, <code class="literal">NCHAR</code>
              does not permit trailing character set information to be
              specified.
            </p></li><li class="listitem"><p>
              <code class="literal">REAL</code>
            </p><p>
              Produces a result of type
              <a class="link" href="floating-point-types.html" title="11.2.3 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE"><code class="literal">REAL</code></a>. This is actually
              <code class="literal">FLOAT</code> if
              <code class="literal">REAL_AS_FLOAT</code> SQL mode
              is enabled; otherwise the result is of type
              <code class="literal">DOUBLE</code>.
            </p></li><li class="listitem"><p>
              <code class="literal">SIGNED [INTEGER]</code>
            </p><p>
              Produces a signed integer value.
            </p></li><li class="listitem"><p>
              <code class="literal">TIME</code>
            </p><p>
              Produces a <a class="link" href="time.html" title="11.3.2 The TIME Type"><code class="literal">TIME</code></a> value.
            </p></li><li class="listitem"><p>
              <code class="literal">UNSIGNED [INTEGER]</code>
            </p><p>
              Produces an unsigned integer value.
</p></li></ul>
</div>
</li></ul>
</div>

</div>

<br />
        </div>

                <div id="docs-in-page-nav-container">
            <div id="docs-in-page-nav">
                
    <a href="fulltext-search-mecab.html"
        aria-label="Previous" title="Previous: MeCab Full-Text Parser Plugin"><span
        class="icon-chevron-left"></span> PREV</a> &nbsp;
<a href="index.html" aria-label="Start" title="Start"> HOME</a> &nbsp;
        <a aria-label="Up" href="functions.html" title="Up: Functions and Operators"> UP</a> &nbsp;
    <a href="xml-functions.html" aria-label="Next"
        title="Next: XML Functions">NEXT <span
        class="icon-chevron-right"></span></a>
            </div>
        </div>
        
         <div id="docs-body-extra">
             
<a class="docs-sidebar-section" href=""><span class="icon-related"></span>
    <span class="text">Related Documentation</span></a>
<div class="docs-sidebar-accordian">
    <div class="text">
        <a href="/doc/relnotes/mysql/8.0/en/">MySQL 8.0 Release Notes</a><br />
        <a href="/doc/dev/mysql-server/latest/">MySQL 8.0 Source Code Documentation</a><br />
        </div>
</div>

    <a class="docs-sidebar-section" href=""><span class="icon-download-thin"></span>
        <span class="text">
            Download
                            this Manual
                    </span>
    </a>
    <div class="docs-sidebar-accordian">
        <div class="text">
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.pdf">PDF (US Ltr)</a>
            - 46.1Mb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.a4.pdf">PDF (A4)</a>
            - 46.1Mb<br />
                        <a href="https://downloads.mysql.com/docs/mysql-ref-manual-8.0-en-pdf-1-20190611.noarch.rpm">PDF (RPM)</a>
            - 41.5Mb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.html-chapter.tar.gz">HTML Download (TGZ)</a>
            - 10.6Mb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.html-chapter.zip">HTML Download (Zip)</a>
            - 10.6Mb<br />
                        <a href="https://downloads.mysql.com/docs/mysql-ref-manual-8.0-en-html-chapter-1-20190611.noarch.rpm">HTML Download (RPM)</a>
            - 9.1Mb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.man-gpl.tar.gz">Man Pages (TGZ)</a>
            - 220.4Kb<br />
                        <a href="https://downloads.mysql.com/docs/refman-8.0-en.man-gpl.zip">Man Pages (Zip)</a>
            - 325.8Kb<br />
                        <a href="https://downloads.mysql.com/docs/mysql-8.0.info.gz">Info (Gzip)</a>
            - 4.1Mb<br />
                        <a href="https://downloads.mysql.com/docs/mysql-8.0.info.zip">Info (Zip)</a>
            - 4.1Mb<br />
                    </div>
    </div>

<a class="docs-sidebar-section" href=""><span class="icon-book"></span>
    <span class="text">Excerpts from this Manual</span></a>
<div class="docs-sidebar-accordian">
    <div class="text">
                <a href="/doc/mysql-backup-excerpt/8.0/en/">MySQL Backup and Recovery</a><br />
                <a href="/doc/mysql-g11n-excerpt/8.0/en/">MySQL Globalization</a><br />
                <a href="/doc/mysql-infoschema-excerpt/8.0/en/">MySQL Information Schema</a><br />
                <a href="/doc/mysql-installation-excerpt/8.0/en/">MySQL Installation Guide</a><br />
                <a href="/doc/mysql-security-excerpt/8.0/en/">Security in MySQL</a><br />
                <a href="/doc/mysql-startstop-excerpt/8.0/en/">Starting and Stopping MySQL</a><br />
                <a href="/doc/mysql-linuxunix-excerpt/8.0/en/">MySQL and Linux/Unix</a><br />
                <a href="/doc/mysql-windows-excerpt/8.0/en/">MySQL and Windows</a><br />
                <a href="/doc/mysql-osx-excerpt/8.0/en/">MySQL and OS X</a><br />
                <a href="/doc/mysql-solaris-excerpt/8.0/en/">MySQL and Solaris</a><br />
                <a href="/doc/mysql-sourcebuild-excerpt/8.0/en/">Building MySQL from Source</a><br />
                <a href="/doc/mysql-reslimits-excerpt/8.0/en/">MySQL Restrictions and Limitations</a><br />
                <a href="/doc/mysql-partitioning-excerpt/8.0/en/">MySQL Partitioning</a><br />
                <a href="/doc/mysql-secure-deployment-guide/8.0/en/">MySQL Secure Deployment Guide</a><br />
                <a href="/doc/mysql-tutorial-excerpt/8.0/en/">MySQL Tutorial</a><br />
                <a href="/doc/mysql-perfschema-excerpt/8.0/en/">MySQL Performance Schema</a><br />
                <a href="/doc/mysql-replication-excerpt/8.0/en/">MySQL Replication</a><br />
                <a href="/doc/mysql-repo-excerpt/8.0/en/">Using the MySQL Yum Repository</a><br />
            </div>
</div>
         </div>

              </div>
     </div>

</div>

<script>
$(function() {
    var doc = new $.doc({ 'mobile': $.browser.mobile, 'docId': 1, 'highlight': true });
});
</script>
    

            
        </div>
    </div>

    <footer class="collapsed">
        <div id="footer-bottom">
                                    <div id="footer-collapse">
                <a href="" id="expand-footer"
                    aria-label="Expand Footer"
                    title="Expand Footer"><span
                    class="icon-plus-square"></span></a>
            </div>
                        <div class="footer-contact">
                <div id="footer-contact-icon" style="display: none;">
                    <span class="icon-call-phone"></span>
                </div>
                <div id="footer-contact-numbers" style="display: none;">
                    <strong>Contact MySQL Sales</strong><br/>
                    USA/Canada: +1-866-221-0634 &nbsp;
                    (<a href="https://www.mysql.com/about/contact/phone/">More Countries &raquo;</a>)
                </div>
                <div id="footer-contact-copyright" style="display: inline-block;">
                    <a href="http://www.oracle.com/" aria-label="Oracle" title="Oracle"><span class="oracle-logo"></span></a>
                    &nbsp; &copy; 2019, Oracle Corporation and/or its affiliates
                </div>
            </div>
            <div class="social-icons">
                <a aria-label="Join us on Facebook" title="Join us on Facebook" href="http://www.facebook.com/mysql"><span class="icon-facebook-square"></span></a>
                <a aria-label="Follow us on Twitter" title="Follow us on Twitter" href="https://twitter.com/mysql"><span class="icon-twitter-square"></span></a>
                <a aria-label="Follow us on LinkedIn" title="Follow us on LinkedIn" href="https://www.linkedin.com/company/mysql"><span class="icon-linkedin-square"></span></a>
                <a aria-label="Visit our YouTube channel" title="Visit our YouTube channel" href="http://www.youtube.com/mysqlchannel"><span class="icon-youtube-square"></span></a>
            </div>
            <br class="clear" />
        </div>
        <div id="footer-links">

            <div id="footer-nav"></div>

            <div class="links">
                <ul>
                    <li class="top"><a href="https://www.mysql.com/products/">Products</a></li>
                    <li><a href="https://www.mysql.com/cloud/">Oracle MySQL Cloud Service</a></li>
                    <li><a href="https://www.mysql.com/products/enterprise/">MySQL Enterprise Edition</a></li>
                    <li><a href="https://www.mysql.com/products/standard/">MySQL Standard Edition</a></li>
                    <li><a href="https://www.mysql.com/products/classic/">MySQL Classic Edition</a></li>
                    <li><a href="https://www.mysql.com/products/cluster/">MySQL Cluster CGE</a></li>
                    <li><a href="https://www.mysql.com/oem/">MySQL Embedded (OEM/ISV)</a></li>
                </ul>
            </div>

            <div class="links">
                <ul>
                    <li class="top"><a href="https://www.mysql.com/services/">Services</a></li>
                    <li><a href="https://www.mysql.com/training/">Training</a></li>
                    <li><a href="https://www.mysql.com/certification/">Certification</a></li>
                    <li><a href="https://www.mysql.com/consulting/">Consulting</a></li>
                    <li><a href="https://www.mysql.com/support/">Support</a></li>
                </ul>
            </div>

            <div class="links">
                <ul>
                    <li class="top"><a href="https://dev.mysql.com/downloads/">Downloads</a></li>
                    <li><a href="https://dev.mysql.com/downloads/mysql/">MySQL Community Server</a></li>
                    <li><a href="https://dev.mysql.com/downloads/cluster/">MySQL NDB Cluster</a></li>
                    <li><a href="https://dev.mysql.com/downloads/shell/">MySQL Shell</a></li>
                    <li><a href="https://dev.mysql.com/downloads/router/">MySQL Router</a></li>
                    <li><a href="https://dev.mysql.com/downloads/workbench/">MySQL Workbench</a></li>
                </ul>
            </div>

            <div class="links">
                <ul>
                    <li class="top"><a href="https://dev.mysql.com/doc/">Documentation</a></li>
                    <li><a href="https://dev.mysql.com/doc/refman/en/">MySQL Reference Manual</a></li>
                    <li><a href="https://dev.mysql.com/doc/workbench/en/">MySQL Workbench</a></li>
                    <li><a href="https://dev.mysql.com/doc/index-cluster.html">MySQL NDB Cluster</a></li>
                    <li><a href="https://dev.mysql.com/doc/index-connectors.html">MySQL Connectors</a></li>
                    <li><a href="https://dev.mysql.com/doc/#topic">Topic Guides</a></li>
                </ul>
            </div>

            <div class="links">
                <ul>
                    <li class="top"><a href="https://www.mysql.com/about/">About MySQL</a></li>
                    <li><a href="https://www.mysql.com/about/contact/">Contact Us</a></li>
                                                            <li><a href="https://www.mysql.com/buy-mysql/">How to Buy</a></li>
                    <li><a href="https://www.mysql.com/partners/">Partners</a></li>
                    <li><a href="https://www.mysql.com/about/jobs/">Job Opportunities</a></li>
                    <li><a href="https://www.mysql.com/sitemap.html">Site Map</a></li>
                </ul>
            </div>

            
            <div id="footer-logo">
                <a href="http://www.oracle.com/" aria-label="Oracle" title="Oracle"><span class="oracle-logo"></span></a>
                &nbsp; &copy; 2019, Oracle Corporation and/or its affiliates
                <div class="footer-legal-links">
                    <a href="https://www.mysql.com/about/legal/">Legal Policies</a> |
                    <a href="http://www.oracle.com/us/legal/privacy/index.htm">Your Privacy Rights</a> |
                    <a href="http://www.oracle.com/us/legal/terms/index.html">Terms of Use</a> |
                    <a href="http://www.oracle.com/us/legal/third-party-trademarks/index.html">Trademark Policy</a> |
                    <a href="http://www.oracle.com/technetwork/community/oca-486395.html">Contributor Agreement</a> |
                    <div id="teconsent" style="display: inline-block"><script async="async" type="text/javascript" src="js/notice.js" crossorigin=""></script></div>
                </div>
            </div>

        </div>
    </footer>
</div>

        <script src="js/s_code_remote.js"></script>

        
    
</body>
</html>
